/*
* @Author: yyf
* @Create: 2018/4/13
* @description: 事件——相关投融资事件组件
*/
<template>
    <div class="custom-box p-20 m-t-20">
        <el-row class="custom-title m-b-20">
            <el-button type="primary" round @click="getEventExitPage"><span class="event-title">相关投融资事件</span></el-button>
        </el-row>
        <el-table :data="eventFinancingData">
            <el-table-column label="ID" prop="id"></el-table-column>
            <el-table-column label="投融资事件名称" prop="investName"></el-table-column>
            <el-table-column label="投资机构" prop="investType">
                <template slot-scope="scope">
                    {{scope.row.investType | getDicNameById('companyIdentity')}}
                </template>
            </el-table-column>
            <el-table-column label="基金" prop="fundName"></el-table-column>
            <el-table-column label="投资金额" prop="investMoney"></el-table-column>
            <el-table-column label="投资时间" prop="investTime">
                <template slot-scope="scope">
                    {{scope.row.investTime | cmsMoment}}
                </template>
            </el-table-column>
            <el-table-column label="是否参与计算">
                <template slot-scope="scope">
                    <el-select v-model="eventFinancingData[scope.$index].canCalculate" @change="changeCanCalculate(scope.row)">
                        <el-option label="计算" :value="1"></el-option>
                        <el-option label="不计算" :value="2"></el-option>
                    </el-select>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script lang="ts">
import Vue from 'vue';
import { Component } from 'vue-property-decorator';
import EventFinancingService from '../../../service/event/event-financing-controller/index';
import { EventFinancingVO, EventFinancingDto } from '../../../api/Interface';
import { EventPublicSearchDto } from '../../../service/event/Interface';
import EventExitService from '../../../service/event/quitor/index';

@Component
export default class TransactionEvent extends Vue {
    // 初始化数据
    public eventPublicSearchDto: EventPublicSearchDto = {} as EventPublicSearchDto;
    public eventFinancingDto: EventFinancingDto = {} as EventFinancingDto;
    public eventFinancingData: Array<EventFinancingVO> = [];
    public eventId: string = '';
    public tabIndex: string = '0';
    public titleName: string = '';
    public id: string = ''; // 主id
    public businessIds: string = ''; // 退出方id （机构id、投资人id、企业id）
    public canCalculate: number = 1; // 是否参与计算: 1:是,2:否 ,
    public addInvestorDialog: boolean = false;
    public enterpriseDialog: boolean = false;
    public exitBusinessIds: number[] = []; // 退出方businessId

    // 声明周期钩子
    public mounted() {
        this.eventId = this.$route.params.eventId;
        this.getEventFinancingPage();
    }
    // 获取退出方列表
    public async getEventExitPage() {
        this.eventPublicSearchDto['pageParam.pageIndex'] = 1;
        this.eventPublicSearchDto['pageParam.pageParam'] = 10;
        this.eventPublicSearchDto.eventId = this.eventId;
        const res = await EventExitService.getEventExitPage(this.eventPublicSearchDto);
        if (res.resCode === '0') {
            const businessIds = res.data.map(item => {
                return item.businessId;
            });
            if (businessIds.length > 0) {
                this.exitBusinessIds = Array.from(new Set(businessIds));
                this.generateEventFinancing();
            }
        }
    }
    // 获取投融资事件列表
    public async getEventFinancingPage() {
        this.eventPublicSearchDto['pageParam.pageIndex'] = 1;
        this.eventPublicSearchDto['pageParam.pageParam'] = 10;
        this.eventPublicSearchDto.eventId = this.eventId;
        const res = await EventFinancingService.eventFinancingPage(this.eventPublicSearchDto);
        if (res.resCode === '0') {
            this.eventFinancingData = res.data.resultData;
        }
    }
     // 重新生成投融资事件
    public async generateEventFinancing() {
        this.eventFinancingDto.businessIds = this.exitBusinessIds;
        this.eventFinancingDto.eventId = Number(this.eventId);
        this.eventFinancingDto.id = 0;
        await EventFinancingService.generateEventFinancing(this.eventFinancingDto );
    }
    // 是否参与计算
    public async changeCanCalculate(item: EventFinancingVO) {
        const eventPublicSearchDto = {
            businessIds: [item.investId],
            canCalculate: item.canCalculate,
            eventId: item.eventId,
            id: item.id
        };
        const res = await EventFinancingService.canCalculate(eventPublicSearchDto);
        if (res.resCode === '0') {
            this.getEventFinancingPage();
        }
    }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .event-title {
        color: #fff;
        font-size: 16px;
    }
</style>
